from django.contrib import admin
from models import Studio,TempModel,DeployAccount
from common.admin_ex import field
from common import dt
# Register your models here.

class StudioAdmin(admin.ModelAdmin):
    list_display=['get_name','temp','get_down_link']
    # list_display_links = ('name',)

    class Media:
        js = ('js/cus_add_studio_button.js',
        )    
    readonly_fields=['get_name','get_down_link']
    
    @field('name',allow_tags=True,admin_order_field='name')
    def get_name(self,obj):
        return '<a href="/studio/edit/{pk}">{name}</a>'.format(pk=obj.pk,name=obj.name)
    
    @field('Download',allow_tags=True)
    def get_down_link(self,obj):
        if obj.freeze.last_zip:
            # zip_time=obj.freeze.last_zip.strftime('%Y-%m-%d %H:%M:%S')
            zip_time=dt.local_str(obj.freeze.last_zip)
            return '<a href="/studio/download/{name}/">{zip_time}</a>'.format(name=obj.name,zip_time=zip_time)
        else:
            return ''


# admin.site.disable_action('delete_selected')
admin.site.register(Studio, StudioAdmin)
admin.site.register(TempModel)
admin.site.register(DeployAccount)